package com.musicxapp.modules.util;

import androidx.annotation.NonNull;

import java.io.IOException;
import java.util.Map;

import okhttp3.FormBody;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.RequestBody;
import okhttp3.Response;

public class KuwoRequest {
    private static OkHttpClient client;
    static {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        builder.addInterceptor(new Interceptor() {
            @NonNull
            @Override
            public Response intercept(@NonNull Chain chain) throws IOException {
                okhttp3.Request request = chain.request().newBuilder()
                        .addHeader("User-Agent",
                                "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36")
                        .addHeader("Referer","https://www.kuwo.cn/")
                        .addHeader("Host","www.kuwo.cn")
                        .addHeader("csrf","3E7JFQ7MRPL")
                        .addHeader("Content-Type","application/json;charset=UTF-8")
                        .addHeader("origin","https://www.kuwo.cn/")
                        .addHeader("Cookie","Hm_lvt_cdb524f42f0ce19b169a8071123a4797=1623339177,1623339183; _ga=GA1.2.1195980605.1579367081; Hm_lpvt_cdb524f42f0ce19b169a8071123a4797=1623339982; kw_token=3E7JFQ7MRPL; _gid=GA1.2.747985028.1623339179; _gat=1")
                        .build();
                return chain.proceed(request);
            }
        });
        client = builder.build();
    }
    public static Response getRequest(String url) throws IOException {

        okhttp3.Request.Builder reqBuilder = new okhttp3.Request.Builder();
        okhttp3.Request postRequest = reqBuilder.url(url).get().build();
        Response response = client.newCall(postRequest).execute();
        return response;
    }
}
